const Koa = require('koa');
const app = new Koa();
var bodyParser = require('koa-bodyparser');
const render = require('koa-art-template');
const Router  = require('koa-router')
const {resolve} = require('path');
app.use(bodyParser());
const requireDirectory = require('require-directory');
render(app, {
    root: resolve(__dirname, 'views'),
    extname: '.html', //后缀也可以写成.art
    debug: process.env.NODE_ENV !== 'production'
  });
/* 导入模块的时候会触发whenLoadModule这个函数 */
requireDirectory(module,'./routers',{visit:whenLoadModule});
function whenLoadModule(obj){
    //判断模块是否是路由
    if(obj instanceof Router){
        app.use(obj.routes())
    }
}
app.listen(8080)